<?php
/**
 * User: 1971229701@qq.com
 * Date: 2020/9/9/009
 * Time: 14:09
 */

namespace app\move\logic;


use app\common\helper\StatusCode;
use app\common\model\Cate;
use app\common\model\IndexBanner;
use app\common\model\Lists;
use app\common\model\Video;
use think\db\Where;

/**
 * Class IndexLogic
 * @package app\index\logic
 */
class IndexLogic extends BaseLogic
{

    public function banner()
    {

        $r = IndexBanner::where('state', StatusCode::DEFAULT_ONE)->select();

        return $r;
    }

    public function cate()
    {
        $r = Cate::order(['sort' => 'asc', 'create_time' => 'desc'])->select();
        return $r;
    }

    public function lists($params)
    {

        !empty($params['id']) && $where['pid'] = $params['id'];

        $where['hot'] = StatusCode::DEFAULT_ONE;

        $where_or['tuijian'] = StatusCode::DEFAULT_ONE;

        if (!empty($params['title']))
        {
            $where_or = [];
            $where = [
                ['title', 'like', '%'.$params['title'].'%'],
            ];
        }

        $r = Lists::where($where)
            ->whereOr($where_or)
            ->field(true)
            ->limit($this->getPagingParams())
            ->order(['sort' => 'asc', 'create_time' => 'desc'])
            ->select();
        return $r;
    }

    public function video($type,$pid)
    {
        $where['type'] = StatusCode::DEFAULT_ONE;

        !empty($type) && $where['type'] = $type;
        !empty($pid) && $where['pid'] = $pid;

        $r = Video::where($where)->field(true)->limit(3)->order(['sort' => 'asc', 'create_time' => 'desc'])->select();
        return $r;
    }

}